﻿

<?php
include "connect/connect_dsccmis.php";
mysql_query("set names tis620");
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Content-type: text/xml;  charset=TIS-620");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
//XML Header
header("content-type:text/xml");

createKmlFile();
function parseToXML($htmlStr)
{ 

$xmlStr=str_replace('<','&lt;',$htmlStr); 

$xmlStr=str_replace('>','&gt;',$xmlStr); 

$xmlStr=str_replace('"','&quot;',$xmlStr); 

$xmlStr=str_replace("'",'&#39;',$xmlStr); 

$xmlStr=str_replace("&",'&amp;',$xmlStr); 

return $xmlStr; 

} 


function createKmlFile(){

		$occProvincestr = "";
		$occProvincestr1 = "";
		$occProvince = $_GET["OccProvince"];
		$occProvincexx = $_GET["OccProvince"];
		
			$occProvince90 = $_GET["occProvince90"];
			$occProvince94 = $_GET["occProvince94"];
			$occProvince95 = $_GET["occProvince95"];
			$occProvince96 = $_GET["occProvince96"];
			$occProvince00 = $_GET["occProvince00"];
			if($occProvince00!="00"){
			if($occProvince90=="90") {$occProvincestr=$occProvincestr.",'สงขลา'" 	;$occProvincestr1=$occProvincestr1. ",90"  ; }
			if($occProvince94=="94") {$occProvincestr=$occProvincestr.",'ปัตตานี'" 	;$occProvincestr1=$occProvincestr1. ",94"  ; }
			if($occProvince95=="95") {$occProvincestr=$occProvincestr.",'ยะลา'"	;$occProvincestr1=$occProvincestr1. ",95"  ; }
			if($occProvince96=="96") {$occProvincestr=$occProvincestr.",'นราธิวาส'"	;$occProvincestr1=$occProvincestr1. ",96"  ; }
			$occProvincestr=substr($occProvincestr,1);
			$occProvincestr1=substr($occProvincestr1,1);
			$occProvincestr=" and prv  in (".$occProvincestr.")";	
			$occProvincestr1=" and prv  in (".$occProvincestr1.")";	
			}				
			else	if($occProvince90 == "90"   and
			           $occProvince94 == "94"   and
			           $occProvince95 == "95"   and
			           $occProvince96 == "96"
			
			
			)
			{
			$occProvincestr='';
			$occProvincestr1='';
			}
			else
			{
			if($occProvince90 != "90") {$occProvincestr=$occProvincestr.",'สงขลา'" 	;$occProvincestr1=$occProvincestr1. ",90"  ; }
			if($occProvince94 != "94") {$occProvincestr=$occProvincestr.",'ปัตตานี'" 	;$occProvincestr1=$occProvincestr1. ",94"  ; }
			if($occProvince95 != "95") {$occProvincestr=$occProvincestr.",'ยะลา'"	;$occProvincestr1=$occProvincestr1. ",95"  ; }
			if($occProvince96 != "96") {$occProvincestr=$occProvincestr.",'นราธิวาส'"	;$occProvincestr1=$occProvincestr1. ",96"  ; }
			$occProvincestr=substr($occProvincestr,1);
			$occProvincestr1=substr($occProvincestr1,1);
			$occProvincestr=" and prv not in (".$occProvincestr.")";
			$occProvincestr1=" and prv not in (".$occProvincestr1.")";
			}
			
		$occProvincexx = $occProvincestr;

$query = "select * from mogisvictim where lat is not null and lng is not null ".$occProvincestr;

mysql_query("SET NAMES UTF8");
$result = mysql_query($query);

if (!$result) {

  die('Invalid query: ' . mysql_error());

}



header("Content-type: text/xml");


// Start XML file, echo parent node
//echo $query ;
echo '<farm>';

//while ($row = @mysql_fetch_assoc($resultA)){
//}
// Iterate through the rows, printing XML nodes for each
$id_adr_B=0;
$count=0;
$prv="ปัตตานี";
while ($row = @mysql_fetch_assoc($result)){


  echo '<marker ';
echo 'count="' . 			parseToXML($row['losSum']) . '" ';
echo 'count2="' . 			parseToXML($row['los1']) . '" ';
echo 'count3="' . 			parseToXML($row['los2']) . '" ';
echo 'count4="' . 			parseToXML($row['los3']) . '" ';
echo 'count5="' . 			parseToXML($row['los4']) . '" ';
echo 'count6="' . 			parseToXML($row['los5']) . '" ';
echo 'countGis="' . 			parseToXML($row['losSum']) . '" ';
echo 'name="1" ' 			;
echo 'age="' . 	     		parseToXML($row['address']) . '" ';
 
echo 'address="' . 	     		parseToXML($row['prv']) . '" ';

//echo 'address="' . 	     	 ' จังหวัด'.parseToXML($row['vill_name']) . '" ';

  echo 'lat="' . 			$row['lat'] . '" ';

  echo 'lng="' . 			$row['lng'] . '" ';


  echo '/>';
  $count=0;

}
//###########################################################################################################################################
$query = "select * from gis6868 where lat is not null and lng is not null".$occProvincestr;
$result = mysql_query($query);
if (!$result) {

  die('Invalid query: ' . mysql_error());

}

// Iterate through the rows, printing XML nodes for each
$id_adr_B=0;
$count=0;
$prv="ปัตตานี";
while ($row = @mysql_fetch_assoc($result)){
echo '<marker ';
echo 'count="' . 			parseToXML($row['losSum6868']) . '" ';
echo 'count2="' . 			parseToXML($row['los1Gis']) . '" ';
echo 'count3="' . 			parseToXML($row['los2Gis']) . '" ';
echo 'count4="' . 			parseToXML($row['los3Gis']) . '" ';
echo 'count5="' . 			parseToXML($row['los4Gis']) . '" ';
echo 'count6="' . 			parseToXML($row['los5Gis']) . '" ';
echo 'count22="' . 			parseToXML($row['los16868']) . '" ';
echo 'count33="' . 			parseToXML($row['los26868']) . '" ';
echo 'count44="' . 			parseToXML($row['los36868']) . '" ';
echo 'count55="' . 			parseToXML($row['los46868']) . '" ';
echo 'count66="' . 			parseToXML($row['los56868']) . '" ';
echo 'count6868="' . 			parseToXML($row['losSum6868']) . '" ';
echo 'countGis="' . 			parseToXML($row['losSumGis']) . '" ';
echo 'name="2" ';


echo 'age="' . 	     		parseToXML($row['address']) . '" ';
 
echo 'address="' . 	     		parseToXML($row['prv']) . '" ';
  echo 'lat="' . 			$row['lat'] . '" ';

  echo 'lng="' . 			$row['lng'] . '" ';


  echo '/>';

}

echo $query."\n";
//echo $id_adr_A."\n";
//echo $occProvincestr;

echo '</farm>';


}

?>
